#ifndef SLTSQL_H
#define SLTSQL_H

#include "tracksql.h"
#include "progsql.h"
#include "slotguts.h"
#include "subgamedata.h"
#include "odbc.h"
#include "localcurrency.h"

class SlotsOpts;

//
// All money values are in cents (100 == $1, 25 == $.25, 1 == $.01)
//
// IMPORTANT:  Access to this class is NOT thread-safe.  That's handled at
//			   the next level up (with calls to lock()/unlock()).
//

class SlotsSQL : public ProgressiveTrackSQL
{
	public:
		SlotsSQL(const String& DBDSN, const String& DBLogin, const String& DBPassword);

		int32 getSubGameData(SubGame *subGame);
        int32 setSubGameData(SubGame *subGame);
        int32 archiveSubGameData(int32 gamenum, SubGame *subGame);

        int32 getGuts(SlotGuts *guts);

		int32 getPlayerLimits(const PID& pid, int32 gameId, uint8 machId,
			int32* compFactor);

		int32 saveGame(int32 casinoId, SlotGuts *guts);
		int32 saveSpins(int32 casinoId, SlotGuts *guts);

        int32 getSavedGame(SlotGuts* guts, int32 *gutsid, int32 *gamenum,uint8* bonusgamenum, bool8 *malfunctioned, bool8 *completed);

		bool8 loadGameDataIntoSpin(int32 gamenum, SlotGuts* guts, SlotSpin* spin);
		bool8 loadWinsDataIntoSpin(SlotSpin* spin);
		bool8 loadScatterResultsDataIntoSpin(SlotSpin* spin);
		bool8 loadStopsIntoSpin(SlotSpin* spin, uint8 numStops);
		bool8 loadBonusGamesIntoSpin(SlotSpin* spin);

        int32 deleteSavedGame(int32 gamenum); /// @todo

		bool8 getGutsName(int32 gutsId, char* name);
		bool8 completeGame(SlotGuts *guts);

        bool8 createBonusGame(SlotGuts* guts, int32 gamenum, uint8 linenumber, uint8 bonusgamenum, uint8 bonusgametype, uint8 playerchoice, int32 winresult);
        bool8 GetLocale( localCurrency *localCurr );
		
		bool8 getPreferedMachSubId(uint8 machId, uint16 preferedCreditValue, const String& login, bool8 forMoney, uint16* MachSubId);
		bool8 getLastUsedMachSubId(uint8 machId, const String& login, bool8 forMoney, uint16* MachSubId);

#ifdef DEBUGSPIN		
		bool8 getDebugSpins (int32 gutsId, DebugStops& stops, int32& numRecords,PID pid);
#endif


    private:

        bool8 getGutsReels(SlotGuts *guts); 
        bool8 getGutsPayouts(SlotGuts *guts);
        bool8 getGutsPaylines(SlotGuts *guts);
        bool8 getGutsDenominations(SlotGuts *guts);

        int32 createWin(int32 casinoId, 
                        const PID& pid,
                        bool8 forMoney,
                        int32 compFactor,
                        int32 gamenum,
                        uint8 lineid,
                        uint8 payouttypeid,
                        int32 payoutamount,
                        int32 *balance,
                        bool8 jackpot);

        int32 createScatterResults( int32 gamenum,      
                                    int32 scatterpos, 
                     	            uint8 payouttypeid, 
                                    int32 payoutamount,
                     	            bool8 jackpot);

		int32 createSavedGame(const PID& pid, 
                              uint8 machid, 
                              int16 creditValue, 
                              bool8 forMoney,
                              int32 gamenum,
                              int32 gutsid,
                              uint8 bonusGameNum);


        bool8 getWins(int32 gamenum, SlotSpin *spin); /// @todo
                                                           
        bool8 createWheels(SlotSpin *spin);

        bool8 getWheels( int32 gamenum, SlotSpin *spin); /// @todo

        bool8 getGame(int32 gamenum, int32 *bet, uint8 *linesbet, int32 *payout); /// @todo
};

#endif
